package ams.model.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.struts2.json.annotations.JSON;

@Entity
@Table(name = "t_role")
public class Role {

	// 角色id
	private Integer id;
	// 角色名称
	private String name;
	// 角色编码
	private String code;
	// 角色描述
	private String description;
	
	private Set<UserRole> userRoles = new HashSet<>();

	private Set<RoleRights> roleRights = new HashSet<>();
	
	

	public Role() {}
	
	public Role(Integer id, String name) {
		super();
		this.id = id;
		this.name = name;
	}



	@Id
	@GeneratedValue
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name", unique = true, nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "code", unique = true, nullable = false)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "description")
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@JSON(serialize=false)
	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	public Set<RoleRights> getRoleRights() {
		return roleRights;
	}

	public void setRoleRights(Set<RoleRights> roleRights) {
		this.roleRights = roleRights;
	}
	
	
	@JSON(serialize=false)
	@OneToMany(mappedBy = "role", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	public Set<UserRole> getUserRoles() {
		return userRoles;
	}

	public void setUserRoles(Set<UserRole> userRoles) {
		this.userRoles = userRoles;
	}

	@Override
	public String toString() {
		return "Role [id=" + id + ", name=" + name + ", code=" + code + ", description=" + description + ", roleRights="
				+ roleRights + "]";
	}

}
